<template>
	<div class="index">
      <el-dialog :title="title" center :visible.sync="log" width="1200px" :close-on-click-modal="false" @close="gianbi">
        <el-table :data="list" border :header-cell-style="{'border-bottom':'solid 1px #d2d3da','text-align':'center','background-color':'#eaeaea'}" style="width: 100%" >

          <el-table-column  prop="date" align="center" label="日期"></el-table-column>

          <el-table-column width="230" label="推广费用">
            <template slot-scope="scope">
              <div style="display: flex;">
                <el-input v-model="scope.row.promote_cost" placeholder="请输入推广费用"></el-input>
                <el-button @click="opentwofrom(scope.$index)" style="margin-left: 10px;" type="text">二级来源</el-button>
              </div>
             
            </template>
          </el-table-column>
          <el-table-column  label="其他费用">
            <template slot-scope="scope">
              <el-input v-model="scope.row.other_cost" placeholder="请输入其他费用"></el-input>
            </template>
          </el-table-column>
          <el-table-column  label="达人订单">
            <template slot-scope="scope">
              <el-input v-model="scope.row.star_order" placeholder="请输入达人订单"></el-input>
            </template>
          </el-table-column>
          <el-table-column  label="短视频订单">
            <template slot-scope="scope">
              <el-input v-model="scope.row.video_order" placeholder="请输入短视频订单"></el-input>
            </template>
          </el-table-column>
          <el-table-column  label="推广订单">
            <template slot-scope="scope">
              <el-input v-model="scope.row.promote_order" placeholder="请输入推广订单"></el-input>
            </template>
          </el-table-column>
          <el-table-column  label="观看成交率">
            <template slot-scope="scope">
              <el-input v-model="scope.row.deal_rate" placeholder="请输入观看成交率">
                <template slot="append">%</template>
              </el-input>
            </template>
          </el-table-column>

          <!-- <el-table-column  label="操作" align="center" >
            <template slot-scope="scope">
              <el-button type="danger" round :disabled="ing" @click="queding(scope.row)">保存</el-button>
            </template>
          </el-table-column> -->

        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button type="danger" round @click="queding()">保存</el-button>
        </div>
      </el-dialog>
      <!-- 二级弹窗 -->
      <el-dialog
        title="二级来源"
        :visible.sync="istwofromshow"
        :close-on-click-modal="false"
        width="500px">
        <el-table
          :data="tableData"
          style="width: 100%">
          <el-table-column
            prop="sub_source"
            label="二级来源名称">
          </el-table-column>
          <el-table-column
            prop="promote_cost"
            label="推广费用">
            <template slot-scope="scope">
                <el-input v-model="scope.row.promote_cost" ></el-input>
            </template>
          </el-table-column>
        </el-table>
        <div style="text-align: center;margin-top: 20px;">
          <el-button  type="danger" round @click="changemoney">确 定</el-button>
        </div>
      </el-dialog>
	</div>
</template>

<script>
  import axios from 'axios'
  import moment from 'moment'
	export default{
		name: 'index',
    props:['source','date2','title'],
		data(){
			return{
        log:true,
        all:{
          source:this.source,
          // start:"",
          // end:""
        },
        list:[],
        times:[],
        istwofromshow:false,
        //可能修改金额
        tableData:[],
        //初始金额
        tableData2:[],
        nowchoose:''
			}
		},
		created() {
      //默认时间
      // this.times = [moment().subtract(7, 'days').format('YYYY-MM-DD 00:00:00'),moment().format('YYYY-MM-DD 00:00:00')]
      // this.all.start = this.times[0]
      // this.all.end = this.times[1]
      this.getlist()
		},
    mounted() {

    },
		methods:{
      gianbi:function(){
        this.$emit('yunxinggengxin')
      },
      queding:function(){
        axios.post('/api/form/source/costs/save3',{data:this.list})
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message.success('更新成功');
              this.getlist()
              this.$emit('yunxinggengxin')
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      getlist:function(){
        axios.get('/api/form/source/costs3',{params:this.all})
          .then(response => {
            if (response.data.msg.code == 0) {
              this.list = response.data.data
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //打开二级来源
      opentwofrom(i){
          this.istwofromshow = true
          this.nowchoose = i
          console.log(i)
          console.log(this.list[i].date)
          console.log(this.list[i].source)
          axios.get('/api/form/sub/source/costs3',{params:{
            source:this.list[i].source,
            date:this.list[i].date
          }})
          .then(response => {
            if (response.data.msg.code == 0) {
              this.tableData = response.data.data
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //确定提交
      changemoney(){
        //修改子金额
        // for(var x=0;x<this.tableData.length;x++){
        //   for(var y=0;y<this.tableData2.length;y++){
        //     if(this.tableData[x].title==this.tableData2[y].title){
        //       if(this.tableData[x].promote_cost!=this.tableData2[y].promote_cost){
        //         console.log('修改数据')
        //         console.log(this.tableData[x])
        //       }
        //     }
        //   }
        // }
        
        //计算总金额
        var con = 0
        for(var x=0;x<this.tableData.length;x++){
          con=con+this.tableData[x].promote_cost*1
        }
        this.istwofromshow = false
        console.log(con)
        this.list[this.nowchoose].promote_cost = con
        axios.post('/api/form/sub/source/costs/save3',{data:this.tableData})
          .then(response => {
            if (response.data.msg.code == 0) {
              this.$message({
                message: '操作成功',
                type: 'success'
              });
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      }

		}
	}
</script>

<style lang="scss" scoped>
	.index{

	}
</style>
